# -*- coding: utf-8 -*-
"""
@Time   : 2023/8/31 00:16
"""

import json
import requests
from mathsolver.init_engine import engine


def func(x):
    return x.replace(",", "，")


def solve(text, options, subquestions):
    raw = {"main": func(text),
           "options": [func(opt) for opt in options],
           "subquestions": [func(sub) for sub in subquestions]}
    # t = requests.get(url="http://172.30.12.34:8304/parse", params=raw).json()
    t = requests.get(url="http://127.0.0.1:8005/parse", params=raw).json()
    print(json.dumps(t["main"], ensure_ascii=False))
    print(json.dumps(t["exprs"], ensure_ascii=False))
    print(json.dumps(t["options"], ensure_ascii=False))
    try:
        solution, conditions, questions = engine.solving(t, verbose=True, raw=raw)
        if solution and not isinstance(solution, str):
            for step in solution.steps:
                for a, b in step["steps"]:
                    print(a, b)
            print(",".join(solution.labels))
            print(solution.funcs)
    except Exception as e:
        print(e)


if __name__ == '__main__':
    js = {"main": "已知a,b∈R, 且a-1+ai与3+2bi相等,则b=().",
          "options": [],
          "subquestions": []}
    aa = js["main"]
    bb = js["options"]
    cc = js["subquestions"]
    solve(aa, bb, cc)
